package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级管理")
public class NursingLevelController {

    @Autowired
    private NursingLevelService nursingLevelService;

    @GetMapping("/listAll")
    @ApiOperation(value = "查询所有护理等级")
    public ResponseResult<List<NursingLevelVo>> selectAll() {
        List<NursingLevelVo> nursingLevelVos = nursingLevelService.selectAll();
        return ResponseResult.success(nursingLevelVos);
    }

    @PostMapping("/insert")
    @ApiOperation(value = "新增护理等级")
    public ResponseResult insertLevel(
            @ApiParam(value = "护理等级信息", required = true)
            @RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.insertLevel(nursingLevelDto);
        return ResponseResult.success();
    }

    @GetMapping("/listByPage")
    @ApiOperation(value = "分页查询护理等级")
    public ResponseResult<PageResponse<NursingLevelVo>> pageLevel(
            @ApiParam(value = "页码", required = true)
            @RequestParam(value = "pageNum") Integer pageNum,
            @ApiParam(value = "页容量", required = true)
            @RequestParam(value = "pageSize") Integer pageSize,
            @ApiParam(value = "护理等级名称")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(value = "护理等级状态")
            @RequestParam(value = "status", required = false) Integer status){
        PageResponse<NursingLevelVo> pageResponse = nursingLevelService.pageLevel(name, status, pageNum, pageSize);
        return ResponseResult.success(pageResponse);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询护理等级")
    public ResponseResult<NursingLevelVo> getLevelById(
            @ApiParam(value = "护理等级id", required = true)
            @PathVariable(value = "id") Long id){
        NursingLevelVo nursingLevelVo = nursingLevelService.getLevelById(id);
        return ResponseResult.success(nursingLevelVo);
    }

    @PutMapping("/update")
    @ApiOperation(value = "更新护理等级")
    public ResponseResult updateLevel(
            @ApiParam(value = "护理等级信息", required = true)
            @RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.updateLevel(nursingLevelDto);
        return ResponseResult.success();
    }

    @DeleteMapping("//delete/{id}")
    @ApiOperation(value = "删除护理等级")
    public ResponseResult deleteLevel(
            @ApiParam(value = "护理等级id", required = true)
            @PathVariable(value = "id") Long id){
        nursingLevelService.deleteLevel(id);
        return ResponseResult.success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "更新护理等级状态")
    public ResponseResult ture_false(
            @ApiParam(value = "护理等级id", required = true)
            @PathVariable Long id,
            @ApiParam(value = "护理等级状态", required = true)
            @PathVariable Integer status){
        nursingLevelService.ture_false(id, status);
        return ResponseResult.success();
    }

}
